package com.breeze.blockchain.mybatis.entity;

import com.breeze.components.mybatis.base.BaseEntity;
import com.mybatisflex.annotation.Table;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 角色权限关联表 实体类。
 *
 * @author breeze
 * @since 2024-05-11 23:21:51
 */
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(title = "角色权限关联表")
@Table("sys_role_permission")
public class RolePermissionDo extends BaseEntity implements Serializable {

  @Serial private static final long serialVersionUID = 1L;

  /** 角色ID */
  @Schema(title = "角色ID")
  private Long roleId;

  /** 权限id */
  @Schema(title = "权限id")
  private Long permissionId;

  public static List<RolePermissionDo> from(RoleDo role, List<Long> permissionIds) {
    return permissionIds.stream()
        .map(
            permissionId ->
                new RolePermissionDo().setRoleId(role.getId()).setPermissionId(permissionId))
        .collect(Collectors.toList());
  }
}
